/* Nuevo trigger para evitar un guion bajo en el codigo de un cubo.
*/ 

CREATE OR REPLACE FUNCTION public.tg_cubosmod_cod()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
  IF REPLACE(NEW.COD,'_','$') <> NEW.COD THEN 
     IF REPLACE(NEW.COD,'_','$') ILIKE '%$%' THEN
        RAISE EXCEPTION 'No se puede usar el guion bajo en el código de un cubo';
     END IF;
  END IF;
  RETURN NEW;
END;
$BODY$;

ALTER FUNCTION public.tg_cubosmod_cod()
    OWNER TO abacouser;

CREATE TRIGGER cubosmod_cod
    AFTER INSERT OR UPDATE 
    ON public.cubosmod
    FOR EACH ROW
    EXECUTE FUNCTION public.tg_cubosmod_cod();
	

-- =====================================================

SELECT aaVersion('488.08','488.07');

-- =====================================================

